/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.delivery.transfers;

import com.mycompany.delivery.dto.AccountDTO;
import com.mycompany.delivery.entities.Account;
import java.util.Objects;

/**
 *
 * @author mhunek
 */
public class AccountT {

    public static Account AccountFromDTO(AccountDTO accountDTO) {
        Account acc = new Account();
        acc.setEnabled(accountDTO.isEnabled());
        acc.setId(accountDTO.getId());
        if (Objects.equals(acc.getId(), 0l)) {
            acc.setId(null);
        }
        acc.setLogin(accountDTO.getLogin());
        acc.setPassword(accountDTO.getPassword());
        acc.setRoles(accountDTO.getRoles());
        return acc;
    }

    public static AccountDTO AccountDTOFromEntity(Account account) {
        AccountDTO acc = new AccountDTO();
        acc.setEnabled(account.isEnabled());
        acc.setId(account.getId());
        acc.setLogin(account.getLogin());
        acc.setPassword(account.getPassword());
        acc.setRoles(account.getRoles());
        return acc;
    }
}
